<?php
namespace BP\GPM;
require_once("BP/En/Map.php");
class Emp extends EntityNoName {
	public function getIsEnable () 
	{
		if ($this->getNo()->equals("admin"))
		{
			return  TRUE ;
		}
		$sql = (("SELECT COUNT(FK_Emp) FROM Port_DeptEmpStation WHERE FK_Emp='" . $this->getNo()) . "'");
		if ((DBAccess->RunSQLReturnValInt($sql, 0) == 0))
		{
			return  FALSE ;
		}
		$sql = (("SELECT COUNT(FK_Emp) FROM Port_DeptEmp WHERE FK_Emp='" . $this->getNo()) . "'");
		if ((DBAccess->RunSQLReturnValInt($sql, 0) == 0))
		{
			return  FALSE ;
		}
		return  TRUE ;
	}
	public function getPinYin () 
	{
		return $this->GetValStrByKey(EmpAttr::$PinYin);
	}
	public function setPinYin ($value) // [String value]
	{
		$this->SetValByKey(EmpAttr::$PinYin, $value);
	}
	public function getHisDept () 
	{
		try 
		{
			return Dept::constructor__String($this->getFK_Dept());
		}
		catch (\RuntimeException $ex)
		{
			throw new \RuntimeException(((((("@获取操作�?" . $this->getNo()) . "部门[") . $this->getFK_Dept()) . "]出现错误,可能是系统管理员没有给他维护部门.@") . $ex->getMessage()));
		}
	}
	public function getFK_Dept () 
	{
		return $this->GetValStrByKey(EmpAttr::$FK_Dept);
	}
	public function setFK_Dept ($value) // [String value]
	{
		$this->SetValByKey(EmpAttr::$FK_Dept, $value);
	}
	public function getFK_DeptText () 
	{
		return $this->GetValRefTextByKey(EmpAttr::$FK_Dept);
	}
	public function getTel () 
	{
		return $this->GetValStrByKey(EmpAttr::$Tel);
	}
	public function setTel ($value) // [String value]
	{
		$this->SetValByKey(EmpAttr::$Tel, $value);
	}
	public function getEmail () 
	{
		return $this->GetValStrByKey(EmpAttr::$Email);
	}
	public function setEmail ($value) // [String value]
	{
		$this->SetValByKey(EmpAttr::$Email, $value);
	}
	public function getPass () 
	{
		return $this->GetValStrByKey(EmpAttr::$Pass);
	}
	public function setPass ($value) // [String value]
	{
		$this->SetValByKey(EmpAttr::$Pass, $value);
	}
	public function getIdx () 
	{
		return $this->GetValIntByKey(EmpAttr::$Idx);
	}
	public function setIdx ($value) // [int value]
	{
		$this->SetValByKey(EmpAttr::$Idx, $value);
	}
	public function getSignType () 
	{
		return $this->GetValIntByKey(EmpAttr::$SignType);
	}
	public function setSignType ($value) // [int value]
	{
		$this->SetValByKey(EmpAttr::$SignType, $value);
	}
	public function CheckPass ($pass) // [String pass]
	{
		if ($this->getPass()->equals($pass))
		{
			return  TRUE ;
		}
		return  FALSE ;
	}
	public static function constructor__ () 
	{
		$me = new self();
		return $me;
	}
	public static function constructor__String ($no) // [String no]
	{
		$me = new self();
		$me->setNo($no->trim());
		if (($me->getNo()->length() == 0))
		{
			throw new \RuntimeException("@要查询的操作员编号为空�??");
		}
		try 
		{
			$me->Retrieve();
		}
		catch (\RuntimeException $ex)
		{
			$i = $me->RetrieveFromDBSources();
			if (($i == 0))
			{
				throw new \RuntimeException(((("@用户或�?�密码错误：[" . $no) . "]，或者帐号被停用。@�?术信�?(从内存中查询出现错误)：ex1=") . $ex->getMessage()));
			}
		}
		return $me;
	}
	public function getHisUAC () 
	{
		$uac = new UAC();
		$uac->OpenForAppAdmin();
		return $uac;
	}
	public function getEnMap () 
	{
		if (($this->get_enMap() != NULL))
		{
			return $this->get_enMap();
		}
		$map = new Map();
		$map->setEnDBUrl(new DBUrl($DBUrlType->AppCenterDSN));
		$map->setPhysicsTable("Port_Emp");
		$map->Java_SetDepositaryOfMap($Depositary->Application);
		$map->Java_SetDepositaryOfEntity($Depositary->Application);
		$map->setEnDesc("用户");
		$map->Java_SetEnType($EnType->App);
		$map->setEnType($EnType->App);
		$map->IndexField = EmpAttr::$FK_Dept;
		$map->AddTBStringPK(EmpAttr::$No, NULL, "登陆账号",  TRUE ,  FALSE , 1, 50, 90);
		$map->AddTBString(EmpAttr::$Name, NULL, "名称",  TRUE ,  FALSE , 0, 200, 130);
		$map->AddTBString(EmpAttr::$Pass, "123", "密码",  FALSE ,  FALSE , 0, 100, 10);
		$map->AddDDLEntities(EmpAttr::$FK_Dept, NULL, "主部�?", Depts::constructor__(),  TRUE );
		$map->AddTBString(EmpAttr::$SID, NULL, "安全校验�?",  FALSE ,  FALSE , 0, 36, 36);
		$map->AddTBString(EmpAttr::$Tel, NULL, "电话",  TRUE ,  FALSE , 0, 20, 130);
		$map->AddTBString(EmpAttr::$Email, NULL, "邮箱",  TRUE ,  FALSE , 0, 100, 132,  TRUE );
		$map->AddTBString(EmpAttr::$PinYin, NULL, "拼音",  TRUE ,  FALSE , 0, 500, 132,  TRUE );
		$map->AddDDLSysEnum(EmpAttr::$SignType, 0, "签字类型",  TRUE ,  TRUE , EmpAttr::$SignType, "@0=不签名@1=图片签名@2=电子签名");
		$map->AddTBInt(EmpAttr::$Idx, 0, "序号",  TRUE ,  FALSE );
		$map->AddSearchAttr(EmpAttr::$SignType);
		$rm = new RefMethod();
		$rm->Title = "设置图片签名";
		$rm->ClassMethodName = ($this . ".DoSinger");
		$rm->refMethodType = $RefMethodType->RightFrameOpen;
		$map->AddRefMethod($rm);
		$rm = new RefMethod();
		$rm->Title = "部门岗位";
		$rm->ClassMethodName = ($this . ".DoEmpDepts");
		$rm->refMethodType = $RefMethodType->RightFrameOpen;
		$map->AddRefMethod($rm);
		$map->getAttrsOfOneVSM()->AddBranches(DeptEmps::constructor__(), Depts::constructor__(), $BP->GPM->DeptEmpAttr->FK_Emp, $BP->GPM->DeptEmpAttr->FK_Dept, "部门维护", EmpAttr::$Name, EmpAttr::$No, "@WebUser.getFK_Dept()");
		$rm = new RefMethod();
		$rm->Title = "修改密码";
		$rm->ClassMethodName = ($this . ".DoResetpassword");
		$rm->getHisAttrs()->AddTBString("pass1", NULL, "输入密码",  TRUE ,  FALSE , 0, 100, 100);
		$rm->getHisAttrs()->AddTBString("pass2", NULL, "再次输入",  TRUE ,  FALSE , 0, 100, 100);
		$map->AddRefMethod($rm);
		$rm = new RefMethod();
		$rm->Title = "修改主部�?";
		$rm->ClassMethodName = ($this . ".DoEditMainDept");
		$rm->refMethodType = $RefMethodType->LinkeWinOpen;
		$map->AddRefMethod($rm);
		$this->set_enMap($map);
		return $this->get_enMap();
	}
	public function DoEditMainDept () 
	{
		return ("../../../GPM/EmpDeptMainDept.htm?FK_Emp=" . $this->getNo());
	}
	public function DoEmpDepts () 
	{
		return ("../../../GPM/EmpDepts.htm?FK_Emp=" . $this->getNo());
	}
	public function DoSinger () 
	{
		return ("../../../GPM/Siganture.htm?EmpNo=" . $this->getNo());
	}
	protected function beforeUpdateInsertAction () 
	{
		$pinyinQP =DataType->ParseStringToPinyin($this->getName())->toLowerCase();
		$pinyinJX =DataType->ParseStringToPinyinJianXie($this->getName())->toLowerCase();
		$this->setPinYin((((("," . $pinyinQP) . ",") . $pinyinJX) . ","));
		$des = DeptEmpStations::constructor__();
		$des->Retrieve(DeptEmpStationAttr::$FK_Emp, $this->getNo());
		$depts = "";
		$stas = "";
		foreach ($des->ToJavaList() as $item) 		{
			$dept = Dept::constructor__();
			$dept->setNo($item->getFK_Dept());
			if (($dept->RetrieveFromDBSources() == 0))
			{
				$item->Delete();
				continue;
			}
			$this->setPinYin((((($this->getPinYin() . $pinyinJX) . "/") .DataType->ParseStringToPinyinJianXie($dept->getName())->toLowerCase()) . ","));
			$sta = Station::constructor__();
			$sta->setNo($item->getFK_Station());
			if (($sta->RetrieveFromDBSources() == 0))
			{
				$item->Delete();
				continue;
			}
			$stas += ((("@" . $dept->getNameOfPath()) . "|") . $sta->getName());
			$depts += ("@" . $dept->getNameOfPath());
		}
		return parent->beforeUpdateInsertAction();
	}
	protected function afterInsertUpdateAction () 
	{
		$sql = (("Select Count(*) From WF_Emp Where No='" . $this->getNo()) . "'");
		$count = DBAccess->RunSQLReturnValInt($sql);
		if (($count == 0))
		{
			$sql = (((((("INSERT INTO WF_Emp (No,Name,Email) VALUES('" . $this->getNo()) . "','") . $this->getName()) . "','") . $this->getEmail()) . "')");
		}
		else
		{
			$sql = (("UPDATE WF_Emp SET Email='" . $this->getEmail()) . "'");
		}
		DBAccess::RunSQL($sql);
		parent->afterInsertUpdateAction();
	}
	public static function GenerPinYin ($no, $name) // [String no, String name]
	{
		$pinyinQP =DataType->ParseStringToPinyin($name)->toLowerCase();
		$pinyinJX =DataType->ParseStringToPinyinJianXie($name)->toLowerCase();
		$py = (((("," . $pinyinQP) . ",") . $pinyinJX) . ",");
		$des = DeptEmpStations::constructor__();
		$des->Retrieve(DeptEmpStationAttr::$FK_Emp, $no);
		$depts = "";
		$stas = "";
		foreach ($des->ToJavaList() as $item) 		{
			$dept = Dept::constructor__();
			$dept->setNo($item->getFK_Dept());
			if (($dept->RetrieveFromDBSources() == 0))
			{
				$item->Delete();
				continue;
			}
			$py = (((($py . $pinyinJX) . "/") .DataType->ParseStringToPinyinJianXie($dept->getName())->toLowerCase()) . ",");
			$sta = Station::constructor__();
			$sta->setNo($item->getFK_Station());
			if (($sta->RetrieveFromDBSources() == 0))
			{
				$item->Delete();
				continue;
			}
			$stas += ((("@" . $dept->getNameOfPath()) . "|") . $sta->getName());
			$depts += ("@" . $dept->getNameOfPath());
		}
		return $py;
	}
	public function DoUp () 
	{
		$this->DoOrderUp(EmpAttr::$FK_Dept, $this->getFK_Dept(), EmpAttr::$Idx);
	}
	public function DoDown () 
	{
		$this->DoOrderDown(EmpAttr::$FK_Dept, $this->getFK_Dept(), EmpAttr::$Idx);
	}
	public function DoResetpassword ($pass1, $pass2) // [String pass1, String pass2]
	{
		if (($pass1->equals($pass2) ==  FALSE ))
		{
			return "两次密码不一�?";
		}
		$this->setPass($pass1);
		$this->Update();
		return "密码设置成功";
	}
	public function getGetNewEntities () 
	{
		return Emps::constructor__();
	}
}
?>
